home *** CD-ROM | disk | FTP | other *** search
- Path: news.panther.net!nemesis!hammy!not-for-mail
- From: gordon@sneaky.lerctr.org (Gordon Burditt)
- Newsgroups: comp.lang.c
- Subject: Re: strncpy bug?
- Date: 16 Mar 1996 16:37:17 -0600
- Organization: What organization?
- Message-ID: <4iffqt$gu4@hammy.lonestar.org>
- References: <ccurtis.826776589@ee.fit.edu>
- NNTP-Posting-Host: news.hammy.lonestar.org
-
- >I was wondering if this is a Linux thing (kernel 1.2.1) or a
- >more general 'problem'. If you call strncpy as such:
- > strncpy( dest, NULL, x );
- >it will seg fault. Is this common among all platforms, or
- >just with Linux?
- >
- >The man page says nothing about it, but I would have presumed
- >that if str[n]cpy were passed NULL as a source, it would
- >merely catenate the destination. Did I presume wrong?
-
- There are a few ANSI C library functions that permit passing NULL
- where a pointer is expected. Very few. If it's not documented
- as OK, you invoke the wrath of undefined behavior. A NULL pointer
- does not meet the definition of a "string". I think this is a complete
- list of ANSI C functions that accept NULL pointers, but I might have
- missed a couple:
-
- (FILE *) NULL
- fflush(NULL) flushes all streams.
- (time_t *) NULL
- time(NULL) doesn't store a copy through its first argument
- in addition to the return value.
- (void *) NULL
- printf family, NULL argument matching a %p conversion may be printed.
- free(NULL) does nothing.
- realloc(NULL, size) acts like malloc(size).
- (char **) NULL
- The 2nd argument of strtod, strtol, and strtoul may be NULL to
- omit returning the pointer to the next character after the converted
- number.
- (char *) NULL (strings)
- strtok (1st argument) NULL indicates continuing to use a
- previously passed string.
- strxfrm may have a NULL 1st argument if the length is 0.
- system(NULL) is used to test whether the facility is available.
- (char *) NULL (buffer)
- setbuf and setvbuf(2nd argument) NULL indicates unbuffered operation.
- (char *) NULL multibyte character functions
- mblen (1st arg), mbtowc (2nd arg), and wctomb(1st arg) accept
- NULL for certain special cases.
-
- Gordon L. Burditt
- sneaky.lerctr.org!gordon
-
-
-